package cn.lliiooll.mt;

import cn.lliiooll.Mentor;
import cn.lliiooll.evt.PlayerChangeMentorEvent;
import cn.lliiooll.evt.PlayerDelMentorEvent;
import cn.lliiooll.evt.PlayerMakeMentorEvent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.UUID;

public class TuDi implements MentorPlayer{

    private Player p;

    public TuDi(Player p){
        this.p = p;
    }

    public ShiFu getShiFu(){
        return new ShiFu(Bukkit.getPlayer((UUID)MentorFile.get(p.getUniqueId().toString(),"shifu")));
    }

    @Override
    public TuDi getTuDi() {
        return new TuDi(p);
    }

    @Override
    public boolean del() {
        if(!has()){
            return false;
        }
        MentorFile.set(p.getUniqueId().toString(),"shifu",null);
        Bukkit.getPluginManager().callEvent(new PlayerDelMentorEvent(p,new ShiFu(Bukkit.getPlayer((UUID) MentorFile.get(this.p.getUniqueId().toString(),"shifu")))));
        return true;
    }

    @Override
    public boolean change(Player p) {
        if(!has()){
            return false;
        }
        MentorFile.set(this.p.getUniqueId().toString(),"shifu",p.getUniqueId().toString());
        Bukkit.getPluginManager().callEvent(new PlayerChangeMentorEvent(p,new ShiFu(Bukkit.getPlayer((UUID) MentorFile.get(this.p.getUniqueId().toString(),"shifu")))));
        return true;
    }

    @Override
    public boolean add(Player p) {
        if(has()){
            return false;
        }
        MentorFile.set(this.p.getUniqueId().toString(),"shifu",p.getUniqueId().toString());
        Bukkit.getPluginManager().callEvent(new PlayerMakeMentorEvent(this.p,new ShiFu(p)));
        return true;
    }

    @Override
    public boolean has() {
        return MentorFile.hasValue(p.getUniqueId().toString(),"shifu");
    }

    @Override
    public Player getPlayer() {
        return p;
    }

}
